﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors.Controls;
using SchoolManagementSystem.Controls;
using CoreData;
using SchoolManagementSystem.Report._4._Kho;
using Helper;

namespace SchoolManagementSystem.Forms.BusinessForm
{
    public partial class frmReportDetailForm : DevExpress.XtraEditors.XtraForm
    {
        public frmReportDetailForm()
        {
            InitializeComponent();
           
        }
        public string PrintFormType { get; set; }
        public long _IDIteam { get; set; }
        public DialogResult ShowDialog(long ID, string Type)
        {
            PrintFormType = Type;
            _IDIteam = ID;
            LoadFormByType();
            this.ShowDialog();
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            return this.DialogResult;
        }
        public DialogResult ShowDialog(Stock_VoucherIn voucherIn, List<Stock_VoucherInDetail> voucherInList)
        {
            ShowPrintForm_VoucherInProposeForm(voucherIn, voucherInList);
            this.ShowDialog();
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            return this.DialogResult;
        }
        public DialogResult ShowDialog(Stock_VoucherOut voucherOut, List<Stock_VoucherOutDetail> voucherOutList)
        {
            ShowPrintForm_VoucherOutProposeForm(voucherOut, voucherOutList);
            this.ShowDialog();
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            return this.DialogResult;
        }
        void LoadFormByType()
        {
            switch (PrintFormType)
            {
                case "VoucherInForm":
                    ShowPrintForm_VoucherInForm();
                    break;
                case "VoucherOutForm":
                    ShowPrintForm_VoucherOutForm();
                    break;
                default:
                    break;
            }
        }
        void ShowPrintForm_VoucherInForm()
        {
            //if (ClassiD == 0)
            //{
            //    MessageControl.ShowMessage("Chưa chọn lớp", "Error", MessageControl.Icon.Error);
            //    return;
            //}
            Stock_VoucherIn vc = new Stock_VoucherIn() { ID = _IDIteam };
            var voucher = (Stock_VoucherIn)RegisterService.RegisterServices.StockVoucherInService.GetVoucherByFilter(vc);
            Stock_VoucherInFromPrint ds = new Stock_VoucherInFromPrint();
            ds.VoucherNo = voucher.VoucherInNo;
            ds.VoucherDate = voucher.VoucherDate;
            ds.EmployeeName = voucher.EmployeeNameExt;
            ds.InputMethod = voucher.Input_MethodNameExt;
            //ds.ProviderName=voucher.p
            ds.PaymentMethod = voucher.PaymentMethodNameExt;
            ds.TotalAmount = voucher.TotalAmount;
            var data = PrintData.GetDataPrintFrom_VoucherIn(voucher.ID);
            ds.DataSource = data;
            printControl1.PrintingSystem = ds.PrintingSystem;
            ds.CreateDocument();
        }
        void ShowPrintForm_VoucherOutForm()
        {
            //if (ClassiD == 0)
            //{
            //    MessageControl.ShowMessage("Chưa chọn lớp", "Error", MessageControl.Icon.Error);
            //    return;
            //}
            Stock_VoucherOut vc = new Stock_VoucherOut() { ID = _IDIteam };
            var voucher = (Stock_VoucherOut)RegisterService.RegisterServices.StockVoucherOutService.GetVoucherByFilter(vc);
            Stock_VoucherInFromPrint ds = new Stock_VoucherInFromPrint();
            ds.VoucherNo = voucher.VoucherOutNo;
            ds.VoucherDate = voucher.VoucherDate;
            ds.EmployeeName = voucher.EmployeeNameExt;
            ds.InputMethod = voucher.Output_MethodNameExt;
            //ds.ProviderName=voucher.p
            ds.PaymentMethod = voucher.PaymentMethodNameExt;
            ds.TotalAmount = voucher.TotalAmount;
            var data = PrintData.GetDataPrintFrom_VoucherOut(voucher.ID);
            ds.DataSource = data;
            printControl1.PrintingSystem = ds.PrintingSystem;
            ds.CreateDocument();
        }
        void ShowPrintForm_VoucherInProposeForm(Stock_VoucherIn voucherIn, List<Stock_VoucherInDetail> voucherInList)
        {            
            StockIn_ProposePrint ds = new StockIn_ProposePrint();
            ds.VoucherNo = voucherIn.VoucherInNo;
            ds.VoucherDate = voucherIn.VoucherDate;
            ds.EmployeeName = voucherIn.EmployeeNameExt;
            ds.InputMethod = voucherIn.Input_MethodNameExt;
            ds.PaymentMethod = voucherIn.PaymentMethodNameExt;
            ds.TotalAmount = voucherIn.TotalAmount;
            ds.Title = "PHIẾU ĐỀ XUẤT MUA HÀNG";
            DataTable dt = new DataTable();          
            var l = new KList<Stock_VoucherOut>();
            dt = l.ConvertToDataTable(voucherInList);
            ds.DataSource = dt;
            printControl1.PrintingSystem = ds.PrintingSystem;
            ds.CreateDocument();
        }

        void ShowPrintForm_VoucherOutProposeForm(Stock_VoucherOut voucherOut, List<Stock_VoucherOutDetail> voucherOutList)
        {
            StockIn_ProposePrint ds = new StockIn_ProposePrint();
            ds.VoucherNo = voucherOut.VoucherOutNo;
            ds.VoucherDate = voucherOut.VoucherDate;
            ds.EmployeeName = voucherOut.EmployeeNameExt;
            ds.InputMethod = voucherOut.Output_MethodNameExt;
            ds.PaymentMethod = voucherOut.PaymentMethodNameExt;
            ds.TotalAmount = voucherOut.TotalAmount;
            ds.Title = "PHIẾU ĐỀ XUẤT BÁN HÀNG";
            DataTable dt = new DataTable();
            var l = new KList<Stock_VoucherOut>();
            dt = l.ConvertToDataTable(voucherOutList);
            ds.DataSource = dt;
            printControl1.PrintingSystem = ds.PrintingSystem;
            ds.CreateDocument();
        }
    }
}
